<script type="text/javascript">
var paginationTotal = 1;//记录总数
var isIE = 0;
if (+[1,]){//非IE
	isIE = 0;	
}else {//IE
	isIE = 1;
	
}
$(function(){
	$("#isIE").val(isIE);
	$("#confirmDialog").dialog({
		autoOpen:false,
		modal:true,
		show:"slide",
		buttons:{
			"<{$lang.ok}>":function(){
				$(this).dialog("close");
			}
		}
	});
	
	$(".print").click(function(){
		if($(".checked:checked").length == 0){
			$("#confirmDialog").html("至少<{$lang.pls}>一项").dialog("open");
			return false;
		}
		reprint();
	});
	
	$(".checkAll").click(function(){
		$(".checkAll").is(":checked")?$(".checked").attr("checked",true):$(".checked").attr("checked",false);
	});
	
	$("#errorTip").dialog({
			autoOpen : false,
			width : 400,
			modal : true,
			show : "slide",
			buttons:{
			"<{$lang.close}>":function(){				
				$(this).dialog("close");			
			}
		}
	});	
	
});

function loadData(page,pageSize){
	var number_code = $('[name=number_code]').val();
	var type = $('[name=type]').val();
	
	loading();
	$.ajax({ //这里使用到Jquery的ajax<{$lang.method}>
		type: "POST",
		async: false,
		dataType: "json",
		url: "/warehouse/print-document/getdocument", //请求的处理url
		data:{
			'number_code':number_code,'type':type
		},
		success: function(json) {
			var list = '';
			if(json.ask != 1){
				list = "<td colspan='7' class=''>&nbsp;"+json.msg+"</td>";
			}else {
				$.each(json.result,function(k,val){
					list += "<tr>";	
					list += '<td><input type="checkbox" class="checked" name="number_codes[]" value="'+val.number_code+'" checked /></td>';
					list += "<td>"+val.number_code+"</td>";	
					if(val.shipping_method){
						list += "<td>"+val.shipping_method+"</td>";
					}else{
						list += "<td>&nbsp;</td>";
					}					
					list += "<td>"+val.status+"</td>";
					list += "<td>"+val.type+"</td>";
					list += "<td>"+val.ref_id+"</td>";
					list += "<td>"+val.create_time+"</td>";
					
					list += "</tr>";
				});
			}
			$("#list").html(list);
			closeLoading();
		}
	}); 
}

function search(){
	var type = $('[name=type]').val();
	var number_code = $('[name=number_code]').val();
	if(number_code==''){
		$("#confirmDialog").html("<{$lang.code}><{$lang.can_not_be_empty}>").dialog("open");
		return false;
	}
	if(type==''){
		$("#confirmDialog").html("<{$lang.pls}><{$lang.type}>").dialog("open");
		return false;
	}
	initData(0);
}

function reprint(){
	var url = '';
	var type = $('[name=type]').val();
	var number_code = $('[name=number_code]').val();
	if(type=='orders'){		//<{$lang.pickup_code}>
		url = '/warehouse/print-document/reprint-order';		
	}
	if(type=='order_pickup'){	//<{$lang.offshelf}>单
		url = '/warehouse/print-document/reprint-offshelf';
	}
	if(type=='receiving'){	//<{$lang.receive_code}>
		url = '/warehouse/print-document/reprint-receiving';
	}
	if(type=='putaway'){	//<{$lang.put_away}>单
		url = '/warehouse/print-document/reprint-putaway';
	}
	
	if(type=='ship_number'){	//<{$lang.shipping}>单
//		url = '/warehouse/print-document/reprint-ship';
		/*var tracking_number = [];	//这里为 <{$lang.shipping}>追踪号    	
    	$('.checked').each(function(i){
			if($(this).attr('checked')){
				tracking_number[i] = $(this).val(); 
			}   			  			 
  		}); 
		openPrint(tracking_number[0]);
		return false;
		*/
		url = '/warehouse/print-document/reprint-ship';
	}
	
	if(type=='hot_print'){	//热敏<{$lang.print}>
		url = '/warehouse/print-document/hot-print';
	}
	
	if(type=='qc_print'){	//  QC<{$lang.print}>

		$.ajax({ //这里使用到Jquery的ajax<{$lang.method}>
			type: "POST",
			async: false,
			dataType: "json",
			url: "/warehouse/print-document/qc-reprint", //请求的处理url
			data:{
				'number_code':number_code,'type':type
			},
			success: function(json) {
				var tip = '';
				if(json.ask != 1){
					$.each(json.msg,function(key,val){
						tip += val+'<br />';	
					});					
					$("#errorTip").html(tip).dialog("open");
				}else {
					var code = number_code.substr(0,1); 
					if(code.toUpperCase() == 'Q'){
						window.open("/product/qc/detail/code/"+ number_code+"/header/0/");  					
					}else{		
						window.open("/product/qc/print-allqc-record/receiving_code/"+ number_code); 					
					}
				}
			}
		}); 
		return;
	}
	
	$("#printForm").attr('action',url).submit(); 
	
}


function setType(){
	var type = $('#type').val();
	$('#reprint_type').val(type);
	search();
}

</script>
<style type="text/css">
.button{background:url(images/left-menu-li.gif) repeat-x left top #F1F6F9; border:1px solid #318DAC; font-weight:bold; padding:2px 5px; font-weight:lighter; color:#318DAC; vertical-align:middle; -moz-border-radius:3px; -webkit-border-radius:3px; margin:auto 5px}
</style>

<div id="iTitle">
	<div id="iTitleSub">
	
		<form id="sForm" name="sForm" onkeypress="if(event.keyCode==13){return false;}">
		<div>
		<label>
			<{$lang.code}>:<input class="myInput" type="text" name="number_code" onkeyup="if(event.keyCode==13){search();}" id="number_code" />
		</label>&nbsp;
		<label>
			<{$lang.type}>:<select name="type" id="type" onchange="setType()" >
				<option value=""><{$lang.pls}></option>
				<option value="orders"><{$lang.pickup_code}></option>					<!-- <{$lang.pickup_code}> -->
				<option value="order_pickup"><{$lang.offshelf_code}></option>		<!-- <{$lang.offshelf}>单 -->
				<option value="receiving"><{$lang.receive_code}></option>		<!-- <{$lang.receive_code}> -->
				<option value="putaway"><{$lang.put_away}><{$lang.code}></option>				<!-- <{$lang.put_away}>单 -->
			</select>
		</label>&nbsp;

		<input class="button" type="button" value="<{$lang.search}>" onclick="search();" />&nbsp;&nbsp;
		<input class="button print" type="button" value=" <{$lang.print}><{$lang.receipt}> " />
		</div>
		</form>
		
	</div>
	<div id="message" style="color:red;"></div>
	<div class="myClear"></div>
</div><!-- id="iTitle" 结束 -->

<h3><{$lang.print}><{$lang.receipt}></h3>

<form id="printForm" action="" method="post" target="_blank">
<input type="hidden" name="reprint_type" id="reprint_type" value="" />
<input type="hidden" name="isIE" id="isIE" value="0" />
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="myTab">	
	<thead><tr>
		<th><input type="checkbox" class="checkAll"/></th>
    	<th><{$lang.code}></th>
    	<th><{$lang.shipping_method}></th>
    	<th><{$lang.status}></th>
		<th><{$lang.type}></th>
		<th><{$lang.referNo}></th>
		<th><{$lang.create}><{$lang.date}></th>
	</tr></thead>
    
	<tbody id="list"></tbody>
	
</table>
</form>
<div id="confirmDialog" title="<{$lang.system}><{$lang.msg}>">	</div>
<div id="errorTip" title="Error tip" style="display:none">	 </div>